/**
 * Copyright 2018 asiainfo Inc.
 **/
package com.myz.service.order.service.impl;

import com.myz.service.order.service.IHelloServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author maoyz on 2018/9/7
 * @version: v1.0
 */
@Service
public class HelloServiceImpl implements IHelloServcie {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;

    @Value("${service.url}")
    private String url;

    @Value("${service.name}")
    private String serviceName;

    @Override
    public String index() {
        List<ServiceInstance> instances = discoveryClient.getInstances(serviceName);
        for (ServiceInstance instance : instances) {
            System.out.println(instance.getUri());
        }

        String object = restTemplate.getForObject(url, String.class);
        return object;
    }
}
